<template>
            <el-form :model="ruleForm2" status-icon  ref="ruleForm2" label-width="100px" class="demo-ruleForm">
          <div class="form-group">
            <input class="form-control" type="text" placeholder="手机号"  @keyup.13="submitForm()" v-model="ruleForm2.loginID" auto-complete="off">
          </div>
          <div class="form-group">
            <input class="form-control" type="password" placeholder="密码" @keyup.13="submitForm()" v-model="ruleForm2.password" auto-complete="off">
          </div>
          <div class="form-group text-right">
            <span @click="dialogFormVisible = true" class="text-info chead">忘记密码</span>
          </div>
          <div class="form-group">
            <el-button type="primary" class="btn-block"  @click="submitForm()">登录</el-button>
          </div>
        </el-form>
</template>

<script>
import { mapMutations } from "vuex";
import { asynclogin } from "../../plugins/api.js";
export default {
  name: "login",
  data() {
    return {
      ruleForm2: {
        loginID: null,
        password: null
      }
    };
  },
  methods: {
    async submitForm() {
      try {
        let data = await asynclogin(this.ruleForm2);
        if (data.userType === "Admin") {
          this.user(data);
          this.$router.push("/admin");
        } else {
          this.$message({
            message: "警告哦，您没有权限登录!",
            type: "warning"
          });
        }
      } catch (err) {
        this.$message({
          message: "警告哦，您没有权限登录!",
          type: "warning"
        });
      }
    },
    guabbi() {
      this.dialogFormVisible = false;
    },
    ...mapMutations({ user: "SET_USERNAME" })
  }
};
</script>

<style scoped>
</style>
